FROM nvcr.io/nvidia/tritonserver:23.12-py3

#apt换源
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list && \
    echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse"  >> /etc/apt/sources.list && \
    apt update && \
    apt install -y \
    git \
    sudo \
    cmake
    	
#python
RUN apt-get install python3.10 python3-pip -y

#pip换源
RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
RUN ln -s /usr/bin/python3 /usr/bin/python

#torch and torchvision use internal network
ARG PIP_ARGS="--trusted-host 192.168.2.229 -i http://192.168.2.229/repository/pypi-group/simple --no-cache-dir"
RUN pip3 install --upgrade pip ${PIP_ARGS} && \
	pip3 install torch==2.5.1+cu121 torchvision==0.20.1+cu121 ${PIP_ARGS}

WORKDIR /opt
RUN git clone https://gitee.com/luo_zhi_cheng/sam2
WORKDIR /opt/sam2
RUN git checkout 2b90b9f5ceec907a1c18123530e92e794ad901a4
# 这一步将会比较漫长，约20-30min
RUN pip3 install -e .

RUN pip3 install opencv-python-headless
# RUN pip3 install onnxruntime-gpu==1.18.0 --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/ --force-reinstall
RUN pip3 install http://192.168.2.229/repository/pypi-local/packages/onnxruntime-gpu/1.18.0/onnxruntime_gpu-1.18.0-cp310-cp310-manylinux_2_28_x86_64.whl
RUN pip3 install matplotlib onnx onnxsim

# 新版本的tritonclient需要的numpy版本太高，没必要
RUN pip3 install tritonclient==2.41.0 tritonclient[all]==2.41.0

# trt-engine-explorer, https://gitee.com/luo_zhi_cheng/TensorRT/tree/v8.6.1/tools/experimental/trt-engine-explorer
WORKDIR /opt
# 目前该容器中的trt版本是8.6.1，但是安装trt-engine-explorer出错，看issue是后续修复 https://github.com/NVIDIA/TensorRT/issues/3711
RUN git clone https://gitee.com/luo_zhi_cheng/TensorRT --branch v10.9.0
WORKDIR /opt/TensorRT/tools/experimental/trt-engine-explorer
RUN python3 -m pip install -e .
RUN apt-get --yes install graphviz
RUN pip3 install tensorrt==10.10.0.31
